﻿// Decompiled with JetBrains decompiler
// Type: Netick.NetworkUnorderedListSnapshot`1
// Assembly: Netick, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6726ECA1-C773-4CF7-8952-E81B30D93B52
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.xml

using System.Collections;
using System.Collections.Generic;

#nullable disable
namespace Netick;

/// <summary>
/// A snapshot of the state of a <see cref="T:Netick.NetworkUnorderedList`1" /> collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
/// </summary>
public struct NetworkUnorderedListSnapshot<T> : IEnumerable<T>, IEnumerable where T : unmanaged
{
  private unsafe int* Ptr;
  private int _itemSize;

  public unsafe int Count => *this.Ptr;

  private unsafe T GetElementData(int index) => *(T*) (this.Ptr + 1 + index * this._itemSize);

  internal unsafe NetworkUnorderedListSnapshot(int* p)
  {
    this.Ptr = p;
    this._itemSize = NetickUtils.GetWordSize(sizeof (T));
  }

  public IEnumerator<T> GetEnumerator()
  {
    int count = this.Count;
    for (int i = 0; i < count; ++i)
      yield return this.GetElementData(i);
  }

  IEnumerator IEnumerable.GetEnumerator() => (IEnumerator) this.GetEnumerator();
}
